package ch04.ex1_5_2_SealedClassesDefiningRestrictedClassHierarchies1

/**
 * Created by caozp-ytcyc2007 on 2017/5/24.
 */

sealed class Expr {
    class Num(val value: Int) : Expr()
    class Sum(val left: Expr, val right: Expr) : Expr()
}

fun eval(e: Expr): Int =
        when (e) {
            is Expr.Num -> e.value
            is Expr.Sum -> eval(e.right) + eval(e.left)
        }
